import { computed } from 'vue'
import useStore from '@/store'
const { cartStore } = useStore()

async function useGoodsInfos() {
  await cartStore.getGoodsInfo()
  const goodsInfos = computed(() => {
    if (cartStore.cartArr && cartStore.goodsInfoArr) {
      const goodsInfos: any = []
      cartStore.cartArr.forEach(item => {
        for (let i = 0; i < cartStore.goodsInfoArr!.length; i++) {
          const e = cartStore.goodsInfoArr![i]
          if (item.goodsInfo_id === e.goodsInfo_id) {
            const goodsInfo = {
              goodsInfo_id: item.goodsInfo_id,
              goods_id: e.goods_id,
              goods_count: item.goods_count,
              goods_image: e.goods_image_path,
              goods_price: e.goods_price,
              goods_name: e.goods_name,
              goods_version: e.cPhone_version_name || '',
              goods_color: e.goods_color_name || '',
              goods_total: e.goods_price * item.goods_count,
              goods_checked: item.goods_checked
            }
            goodsInfos.push(goodsInfo)
            break
          }
        }
      })
      return goodsInfos
    }
  })
  return goodsInfos
}
export default useGoodsInfos
